package com.xzy.mybatis.cipher.support.crypto;

import cn.hutool.crypto.symmetric.AES;
import com.xzy.mybatis.cipher.support.strategy.crypto.CryptoStrategy;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.StandardCharsets;

/**
 * @author xzy.xiao
 * @since 2025/2/21  21:29
 */
@Slf4j
public class MyCryptoStrategy extends CryptoStrategy {

    private final AES aes;

    public MyCryptoStrategy(String key) {
        super(key);
        this.aes = new AES(key.getBytes());
    }

    @Override
    public String getName() {
        return "my_aes";
    }

    @Override
    public String encrypt(String value) {
        log.info("my_aes encrypt");
        return aes.encryptBase64(value);
    }

    @Override
    public String decrypt(String value) {
        log.info("my_aes decrypt");
        return aes.decryptStr(value, StandardCharsets.UTF_8);
    }
}
